﻿using Microsoft.Extensions.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace   com.iot.core.data

{
    public class Sort
    {
        public string Filed { get; set; } = "Id";
        public bool Asc { get; set; } = true;
        public override string ToString()
        {
            var sb = new StringBuilder();

            for (var i = 0; i < Filed.Length; i++)
            {
                if (char.IsUpper(Filed[i]))
                {
                    if (i != 0)
                    {
                        sb.Append("_");
                    }
                    sb.Append(char.ToLower(Filed[i]) );


                }
                else
                {
                    sb.Append(Filed[i]);
                }

            }
            return string.Format("{0} {1}", sb.ToString(), Asc ? "asc" : "desc");
        }
    }
}
